﻿using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System.Text;
using System.Web.Services;
public partial class admin_edit_add_newclient : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["p_id"] = Request.QueryString["id"].ToString();
        Label67.Visible = false;
        Label67.Text = Session["p_id"].ToString();
        if (Page.IsPostBack == true)
        {
        }
        else
        {

            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
            conn.Open();

            SqlCommand cmd = new SqlCommand("select * from  property_buy where p_id='"+Request .QueryString ["id"]+"'", conn);
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
               // Session["p_id"] = dr["p_id"].ToString();

                Response.Write(dr["custom_ctype"].ToString());
                DropDownList52.Items.FindByValue(dr["c_type"].ToString()).Selected = true;
                TextBox61.Text = dr["custom_ctype"].ToString();
               // DropDownList15.Items.FindByValue(dr["a_nme"].ToString()).Selected = true;
                d6.Items.FindByValue(dr["p_type"].ToString()).Selected = true;
                txttype.Text = dr["cust_p_type"].ToString();
                txtfname1.Text = dr["f_name"].ToString();

                txtlname1.Text = dr["l_name"].ToString();
                TextBox22.Text = dr["email_id"].ToString();

                TextBox21.Text = dr["phone"].ToString();

                TextBox20.Text = dr["house_no"].ToString();

                TextBox30.Text = dr["street"].ToString();
                TextBox66.Text = dr["nghr"].ToString();
                TextBox50.Text = dr["city"].ToString();



                TextBox51.Text = dr["country"].ToString();


                TextBox52.Text = dr["zip"].ToString();



                TextBox23.Text = dr["p_city"].ToString();
              
                TextBox26.Text = dr["p_street"].ToString();

                TextBox27.Text = dr["p_nghr"].ToString();

                TextBox28.Text = dr["p_zip"].ToString();
                TextBox29.Text = dr["p_country"].ToString();


                TextBox54.Text = dr["f_roomno"].ToString();


                TextBox56.Text = dr["from_floor"].ToString();


                TextBox5.Text = dr["store"].ToString();
                TextBox55.Text = dr["to_roomno"].ToString();


                TextBox57.Text = dr["to_floor"].ToString();

                TextBox58.Text = dr["occupation"].ToString();



                DropDownList31.Items.FindByValue(dr["saferoom"].ToString()).Selected = true;
                txtsaferoom.Text = dr["custom_saferoom"].ToString();
                DropDownList32.Items.FindByValue(dr["garden"].ToString()).Selected = true;
                txtgarden.Text = dr["custom_garden"].ToString();


                DropDownList32.Items.FindByValue(dr["g_floor"].ToString()).Selected = true;
                TextBox3.Text = dr["custom_g_floor"].ToString();
                DropDownList49.Items.FindByValue(dr["parking"].ToString()).Selected = true;
                TextBox59.Text = dr["cust_parking"].ToString();
                DropDownList50.Items.FindByValue(dr["elevator"].ToString()).Selected = true;
                TextBox60.Text = dr["cust_elevator"].ToString();
                DropDownList16.Items.FindByValue(dr["ac"].ToString()).Selected = true;
                TextBox9.Text = dr["custom_ac"].ToString();

                // =dr["parking"].ToString(); TextBox7.Text);
                //=dr["elevator"].ToString(); TextBox8.Text);


                DropDownList13.Items.FindByValue(dr["prop_cond"].ToString()).Selected = true;
                TextBox12.Text = dr["cust_condtion"].ToString();

                TextBox11.Text = dr["p_size"].ToString();

                DropDownList7.Items.FindByValue(dr["p_size_type"].ToString()).Selected = true;
                txtBalconies.Text = dr["balconies"].ToString();
                TextBox6.Text = dr["balconies_no"].ToString();
                DropDownList46.Items.FindByValue(dr["balcony_type"].ToString()).Selected = true;



                txtBalconies0.Text = dr["balconies1"].ToString();
                TextBox48.Text = dr["balconies_no1"].ToString();
                DropDownList47.Items.FindByValue(dr["balcony_type1"].ToString()).Selected = true;
                TextBox36.Text = dr["a_hours"].ToString();

                DropDownList35.Items.FindByValue(dr["furniture"].ToString()).Selected = true;
                TextBox16.Text = dr["c_furn"].ToString();
                DropDownList17.Items.FindByValue(dr["purpose"].ToString()).Selected = true;
                TextBox18.Text = dr["cust_purpose"].ToString();

                DropDownList34.Items.FindByValue(dr["roof"].ToString()).Selected = true;

                TextBox23.Text = dr["cust_roof"].ToString();

                DropDownList18.Items.FindByValue(dr["finance"].ToString()).Selected = true;

                TextBox24.Text = dr["cust_finance"].ToString();

                TextBox35.Text = dr["budget"].ToString();
                DropDownList51.Items.FindByValue(dr["currency_type"].ToString()).Selected = true;

                DropDownList48.Items.FindByValue(dr["mortage"].ToString()).Selected = true;

                TextBox31.Text = dr["cust_mortage"].ToString();
                TextBox13.Text = dr["comment"].ToString();
                DropDownList18.Items.FindByValue(dr["financing"].ToString()).Selected = true;



            }
            dr.Close();

        }
    }

    protected void Save_Click(object sender, System.EventArgs e)
    {

        string cat = null;
        cat = DropDownList1.SelectedValue;



        SqlConnection conn = null;

        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();



        Random r1 = new Random();
        int num = r1.Next(0, 99999999); // generate random number
        string number = string.Format("{0:D8}", num);

        Random r2 = new Random();
        int num2 = r2.Next(0, 26); // generate random letter
        char letter = (char)('A' + num2);


      //  c_id = letter + number; // join both as ID 

        string p_size = TextBox11.Text + DropDownList7.SelectedValue;

        //  string balcony = DropDownList14.SelectedValue + TextBox6.Text;
        //  SqlCommand cmd = new SqlCommand("Insert into property_buy values(@p_id ,@type,@wants_to,@property,@c_type,@agent_name,@client_fullname,@property_type,@house_no,@city,@street,@ssn,@zip,@country,@email_id,@phone,@room_no,@floor,@store,@ac,@parking,@elevator,@price,@prop_size,@entering_date,@condtion,@balconies,@a_hours,@safe_room,@budget,@purpose,@nghrhood,@comment,@financing,@custom_name,@category,@c_cat,@cat,@adding_by,@date,@status,@detail)", conn);
        SqlCommand cmd = new SqlCommand("update property_buy set type=@type,c_type=@c_type,custom_ctype=@custom_ctype,a_nme=@a_nme,p_type=@p_type, cust_p_type=@cust_p_type, f_name=@f_name, l_name=@l_name, email_id=@email_id, phone=@phone, house_no=@house_no, street=@street,  nghr=@nghr, city=@city,country=@country, zip=@zip,  p_city=@p_city, p_street=@p_street, p_nghr=@p_nghr, p_zip=@p_zip,p_country=@p_country, f_roomno=@f_roomno,  from_floor=@from_floor,  store=@store, to_roomno=@to_roomno,  to_floor=@to_floor,  occupation=@occupation,  saferoom=@saferoom, custom_saferoom=@custom_saferoom, garden=@garden,  custom_garden=@custom_garden,  g_floor=@g_floor,  custom_g_floor=@custom_g_floor,  ac=@ac, custom_ac=@custom_ac, parking=@parking,cust_parking=@cust_parking, elevator=@elevator,cust_elevator=@cust_elevator, prop_cond=@prop_cond, cust_condtion=@cust_condtion,  p_size=@p_size,p_size_type= @p_size_type,balconies=@balconies, balconies_no= @balconies_no, balcony_type=@balcony_type,  balconies1=@balconies1, balconies_no1=@balconies_no1,balcony_type1=@balcony_type1,  a_hours=@a_hours, furniture=@furniture, c_furn=@c_furn,  purpose=@purpose, cust_purpose=@cust_purpose, roof=@roof,  cust_roof=@cust_roof, finance=@finance,  cust_finance=@cust_finance, budget=@budget,currency_type=@currency_type, mortage=@mortage, cust_mortage=@cust_mortage, comment=@comment, financing=@financing, smart_house=@smart_house, alarm=@alarm , bars=@bars, handicap=@handicap,guard=@guard,  gym=@gym,  jacuzie=@jacuzie, pool=@pool,  check_custom=@check_custom,  custom=@custom,comments=@comments, adding_by=@adding_by,  date=@date, status=@status where p_id='" + Request .QueryString ["id"].ToString() + "'", conn);


       // SqlCommand cmd = new SqlCommand("insert into property_buy values(@p_id,@type,@c_type,@custom_ctype,@a_nme,@p_type, @cust_p_type, @f_name, @l_name, @email_id, @phone, @house_no, @street,  @nghr,  @city,@country, @zip,  @p_city, @p_street, @p_nghr, @p_zip, @p_country, @f_roomno,  @from_floor,  @store, @to_roomno,  @to_floor,  @occupation,  @saferoom, @custom_saferoom, @garden,  @custom_garden,  @g_floor,  @custom_g_floor,  @ac, @custom_ac, @parking,@cust_parking, @elevator,@cust_elevator, @prop_cond, @cust_condtion,  @p_size, @p_size_type,@balconies,  @balconies_no,  @balcony_type,  @balconies1, @balconies_no1,@balcony_type1,  @a_hours, @furniture, @c_furn,  @purpose, @cust_purpose, @roof,  @cust_roof,  @finance,  @cust_finance, @budget,@currency_type, @mortage, @cust_mortage, @comment, @financing, @smart_house,  @alarm , @bars, @handicap,@guard,  @gym,  @jacuzie, @pool,  @check_custom,  @custom,@comments, @adding_by,  @date, @status)", conn);

      //  cmd.Parameters.AddWithValue("@p_id", Session["p_id"]);
        cmd.Parameters.AddWithValue("@type", "Buy");
        cmd.Parameters.AddWithValue("@c_type", DropDownList52.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_ctype", TextBox61.Text);
        cmd.Parameters.AddWithValue("@a_nme", DropDownList15.SelectedValue);
        cmd.Parameters.AddWithValue("@p_type", d6.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_p_type", txttype.Text);
        cmd.Parameters.AddWithValue("@f_name", txtfname1.Text);

        cmd.Parameters.AddWithValue("@l_name", txtlname1.Text);
        cmd.Parameters.AddWithValue("@email_id", TextBox22.Text);

        cmd.Parameters.AddWithValue("@phone", TextBox22.Text);

        cmd.Parameters.AddWithValue("@house_no", TextBox20.Text);

        cmd.Parameters.AddWithValue("@street", TextBox30.Text);
        cmd.Parameters.AddWithValue("@nghr", TextBox66.Text);
        cmd.Parameters.AddWithValue("@city", TextBox50.Text);



        cmd.Parameters.AddWithValue("@country", TextBox51.Text);


        cmd.Parameters.AddWithValue("@zip", TextBox52.Text);



        cmd.Parameters.AddWithValue("@p_city", TextBox23.Text);
        cmd.Parameters.AddWithValue("@p_street", TextBox26.Text);

        cmd.Parameters.AddWithValue("@p_nghr", TextBox27.Text);

        cmd.Parameters.AddWithValue("@p_zip", TextBox28.Text);
        cmd.Parameters.AddWithValue("@p_country", TextBox29.Text);


        cmd.Parameters.AddWithValue("@f_roomno", TextBox54.Text);


        cmd.Parameters.AddWithValue("@from_floor", TextBox56.Text);


        cmd.Parameters.AddWithValue("@store", TextBox5.Text);
        cmd.Parameters.AddWithValue("@to_roomno", TextBox55.Text);


        cmd.Parameters.AddWithValue("@to_floor", TextBox57.Text);

        cmd.Parameters.AddWithValue("@occupation", TextBox58.Text);



        cmd.Parameters.AddWithValue("@saferoom", DropDownList31.Text);

        cmd.Parameters.AddWithValue("@custom_saferoom", txtsaferoom.Text);
        cmd.Parameters.AddWithValue("@garden", DropDownList32.Text);
        cmd.Parameters.AddWithValue("@custom_garden", txtgarden.Text);


        cmd.Parameters.AddWithValue("@g_floor", DropDownList32.Text);
        cmd.Parameters.AddWithValue("@custom_g_floor", TextBox3.Text);
        cmd.Parameters.AddWithValue("@parking", DropDownList49.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_parking", TextBox59.Text);
        cmd.Parameters.AddWithValue("@elevator", DropDownList50.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_elevator", TextBox60.Text);
        cmd.Parameters.AddWithValue("@ac", DropDownList16.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_ac", TextBox9.Text);

        // cmd.Parameters.AddWithValue("@parking", TextBox7.Text);
        //cmd.Parameters.AddWithValue("@elevator", TextBox8.Text);


        cmd.Parameters.AddWithValue("@prop_cond", DropDownList13.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_condtion", TextBox12.Text);

        cmd.Parameters.AddWithValue("@p_size", TextBox11.Text);

        cmd.Parameters.AddWithValue("@p_size_type", DropDownList7.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies", txtBalconies.Text);
        cmd.Parameters.AddWithValue("@balconies_no", TextBox6.Text);
        cmd.Parameters.AddWithValue("@balcony_type", DropDownList46.SelectedValue);



        cmd.Parameters.AddWithValue("@balconies1", txtBalconies0.Text);
        cmd.Parameters.AddWithValue("@balconies_no1", TextBox48.Text);
        cmd.Parameters.AddWithValue("@balcony_type1", DropDownList47.SelectedValue);


        cmd.Parameters.AddWithValue("@a_hours", TextBox36.Text);

        cmd.Parameters.AddWithValue("@furniture", DropDownList35.SelectedValue);
        cmd.Parameters.AddWithValue("@c_furn", TextBox16.Text);
        cmd.Parameters.AddWithValue("@purpose", DropDownList17.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_purpose", TextBox18.Text);

        cmd.Parameters.AddWithValue("@roof", DropDownList34.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_roof", TextBox23.Text);

        cmd.Parameters.AddWithValue("@finance", DropDownList18.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_finance", TextBox24.Text);

        cmd.Parameters.AddWithValue("@budget", TextBox35.Text);
        cmd.Parameters.AddWithValue("@currency_type", DropDownList51.SelectedValue);

        cmd.Parameters.AddWithValue("@mortage", DropDownList48.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_mortage", TextBox31.Text);
        cmd.Parameters.AddWithValue("@comment", TextBox13.Text);
        cmd.Parameters.AddWithValue("@financing", DropDownList18.SelectedValue);

        cmd.Parameters.AddWithValue("@smart_house", CheckBox1.Checked);
        cmd.Parameters.AddWithValue("@alarm ", CheckBox2.Checked);
        cmd.Parameters.AddWithValue("@bars", CheckBox3.Checked);
        cmd.Parameters.AddWithValue("@handicap", CheckBox4.Checked);
        cmd.Parameters.AddWithValue("@guard", CheckBox5.Checked);
        cmd.Parameters.AddWithValue("@gym", CheckBox6.Checked);
        cmd.Parameters.AddWithValue("@jacuzie", CheckBox7.Checked);
        cmd.Parameters.AddWithValue("@pool", CheckBox8.Checked);
        cmd.Parameters.AddWithValue("@check_custom", CheckBox13.Checked);

        cmd.Parameters.AddWithValue("@custom", txtcheck.Text);

        cmd.Parameters.AddWithValue("@comments", TextBox13.Text);
        cmd.Parameters.AddWithValue("@adding_by", "admin");
        cmd.Parameters.AddWithValue("@date", System.DateTime.Now);
        cmd.Parameters.AddWithValue("@status", "0");

        cmd.ExecuteNonQuery();

      conn.Close();

        Response.Redirect("propert_for_conf.aspx");


        conn.Close();



    }

    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }

     protected void DropDownList4_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        //Session["type"] = DropDownList5.SelectedValue;
        //Session["proptype"] = DropDownList6.SelectedValue;

       
    }

    protected void Save1_Click(object sender, System.EventArgs e)
    {

    }

//protected void  show_pnl();(object sender, System.EventArgs e)
//{

//}
protected void  Button4_Click(object sender, System.EventArgs e)
{
    
}

protected void CheckBox13_CheckedChanged(object sender, System.EventArgs e)
{
    Label1.Visible = true;
    //TextBox42.Visible = true;
}
protected void DropDownList28_SelectedIndexChanged(object sender, System.EventArgs e)
{

}
protected void DropDownList42_SelectedIndexChanged(object sender, System.EventArgs e)
{

}
protected void DropDownList48_SelectedIndexChanged(object sender, System.EventArgs e)
{
    

}
protected void txtcreate_TextChanged(object sender, System.EventArgs e)
{

}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "action")
    {

        //Label1.Text = "hello";
        int index = Convert.ToSByte(e.CommandArgument);

        GridViewRow row = GridView2.Rows[index];
        SqlDataAdapter adp = new SqlDataAdapter();
        SqlCommand cmd1 = new SqlCommand();
        DataSet ds = new DataSet();


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

        con.Open();

        SqlCommand objectvalue = new SqlCommand("", con);
        cmd1.Connection = con;

        SqlCommand dmc = new SqlCommand("Delete from properties_rent where p_id='" + row.Cells[0].Text + "'", con);
        dmc.ExecuteNonQuery();

        // SqlCommand dmc = new SqlCommand("select p_id from properties where p_id='" + row.Cells[0].Text + "'", con);

        //dmc.ExecuteNonQuery();
        //  Session["p_id"] = row.Cells[0].Text;

        con.Close();
        // Response.Write(Session["p_id"]);
        // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

        Response.Redirect("report_property_for_rent.aspx");
        // con.Close();


    }



    if (e.CommandName == "view")
    {

        //Label1.Text = "hello";
        int index = Convert.ToSByte(e.CommandArgument);

        GridViewRow row = GridView2.Rows[index];
        SqlDataAdapter adp = new SqlDataAdapter();
        SqlCommand cmd1 = new SqlCommand();
        DataSet ds = new DataSet();


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

        con.Open();

        SqlCommand objectvalue = new SqlCommand("", con);
        cmd1.Connection = con;



        SqlCommand dmc = new SqlCommand("select t_id from task where t_id='" + row.Cells[1].ToString() + "'", con);

        dmc.ExecuteNonQuery();
        Session["t_id"] = row.Cells[1].Text.ToString();

        con.Close();
        // Response.Write(Session["p_id"]);
        // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

        Response.Redirect("edit-task.aspx");
        // con.Close();


    }

}

}